package cn.tedu.collection;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author ：Dsi
 * @date ：2021/11/19 11:13
 * Describe ：该类用于测试Set集合
 */
public class TestSet {
    public static void main(String[] args) {
        Set<String> s=new HashSet<>();
        s.add("蜘蛛精");
        s.add("白骨精");
        s.add("狐狸精");
        s.add(null);
        System.out.println(s.isEmpty());
        System.out.println(s.contains("至尊宝"));
        System.out.println(Arrays.toString(s.toArray()));
        Set<String> s2=new HashSet<>();
        s2.add("小老夫");
        s2.add("小是几");
        s2.add("小海腾");
        s.addAll(s2);
        System.out.println(s);
        System.out.println(s2);
        System.out.println(s2.isEmpty());
        System.out.println(s.retainAll(s2));
        System.out.println(s);
        System.out.println(s2);

        Iterator<String> iterator = s2.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
